﻿namespace Infra.Validation
{
    /// <summary>
    /// Validates a set of rules.
    /// </summary>
    /// <typeparam name="T">The object to validate.</typeparam>
    public class RulesSetValidator<T> : IValidator<T> where T : class
    {
        private RulesSet<T> RuleList { get; set; }
        
        public RulesSetValidator(RulesSet<T> ruleList)
        {
            this.RuleList = ruleList;    
        }

        /// <summary>
        /// Validates the specified object.
        /// </summary>
        /// <param name="objectToValidate">The object to validate.</param>
        /// <returns></returns>
        public ValidationResult Validate(T objectToValidate)
        {
            var validationResult = new ValidationResult();

            foreach (var currentRule in this.RuleList)
            {
                currentRule.ValidateWithResult(objectToValidate, validationResult);
            }

            return validationResult;
        }
    }
}
